package com.hy.study.order;

import com.hy.study.bean.OrderBean;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 分组排序
 */
public class OrderGroupingComparator extends WritableComparator {
    public OrderGroupingComparator(){
        //创建一个构造函数，将比较类传递给调用者
        super(OrderBean.class,true);
    }

    //这里要求只要id 相等 就是相同的key
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        int result;
        OrderBean sourceBean = (OrderBean) a;
        OrderBean targetBean = (OrderBean) b;
        if (sourceBean.getOrderId() > targetBean.getOrderId()) {
            result = 1;
        } else if (sourceBean.getOrderId() < targetBean.getOrderId()) {
            result = -1;
        } else {
            result = 0;
        }
        return result;


    }
}
